package com.treeroot.commonutils.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description:  mybatisPlus
 * 自动处理插入生成时间 修改时间
 * @Author:treeRoot
 * @Email:553503639@qq.com
 * @Date: Create in 11:34 / 2022/4/19
 */

/**    new Date()
 * public Date() {
 *         this(System.currentTimeMillis());取得当前系统时间，
 *     }
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreate", new Date(), metaObject);

        this.setFieldValByName("gmtModified", new Date(), metaObject);
        this.setFieldValByName("payTime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified", new Date(), metaObject);
    }
}
